//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "UI/Types/UIAction.h"

namespace Engine
{
namespace UI
{

	//
	// Action Manager
	//

	class ActionManager
	{
	// types
	private:
		typedef map< string, UIAction >		action_map_t;


	// variables
	private:
		action_map_t		_actions;


	// methods
	public:
		ActionManager () {}
		~ActionManager () {}

		// Actions //
		void AddAction (uni_c_string name, const UIAction &action);
		void RemoveAction (const UIAction &action);
		void RemoveAction (uni_c_string name);
		bool GetAction (uni_c_string name, UIAction &action) const;

		void Clear ();
	};

	
	
/*
=================================================
	AddAction
=================================================
*/
	inline void ActionManager::AddAction (uni_c_string name, const UIAction &action)
	{
		ASSERT( not _actions.IsExist( name ) );

		_actions.Add( name, action );
	}
	
/*
=================================================
	RemoveAction
=================================================
*/
	inline void ActionManager::RemoveAction (const UIAction &action)
	{
		FOR( i, _actions )
		{
			if ( _actions[i].second == action )
			{
				_actions.EraseFromIndex( i );
				return;
			}
		}

		WARNING( "Action not found!" );
	}
	
/*
=================================================
	RemoveAction
=================================================
*/
	inline void ActionManager::RemoveAction (uni_c_string name)
	{
		usize	idx = -1;

		if ( _actions.FindIndex( name, idx ) )
		{
			_actions.EraseFromIndex( idx );
			return;
		}

		WARNING( "Action not found!" );
	}
	
/*
=================================================
	GetAction
=================================================
*/
	inline bool ActionManager::GetAction (uni_c_string name, UIAction &action) const
	{
		usize	idx = -1;

		if ( _actions.FindIndex( name, idx ) )
		{
			action = _actions[idx].second;
			return true;
		}
		return false;
	}
	
/*
=================================================
	Clear
=================================================
*/
	inline void ActionManager::Clear ()
	{
		_actions.Clear();
	}


}	// UI
}	// Engine
